package com.oyjd.business.condsel.activity;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.oyjd.R;
import com.oyjd.framework.ui.condsel.CondSelect;
import com.oyjd.framework.ui.condsel.CondSelectSimple;
import com.oyjd.framework.ui.condsel.CondSimpleVO;
import com.oyjd.framework.ui.condsel.OnCondListener;



public class CondSelActivity extends Activity {

	private CondSelect fl;
	private Button bt;

	private CondSelectSimple scs;
	private TextView tv;

	@SuppressLint("ResourceAsColor")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.act_condsel);

		fl = (CondSelect) findViewById(R.id.fl);
		// fl.getMask().setBackgroundColor(Color.GRAY);
		fl.setOnCondListener(new OnCondListener() {

			@Override
			public void OnSelected(int pos1, int pos2) {
				Log.i("OnSelected", pos1 + "----" + pos2);
			}

			@Override
			public void OnMoving(int pos1, int pos2) {
				Log.i("OnMoving", pos1 + "----" + pos2);

			}
		});
		//
		List<View> data = new ArrayList<View>();
		int[] c = { Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW };
		for (int i = 0; i < c.length; i++) {
			TextView tv = new TextView(this);
			tv.setBackgroundColor(c[i]);
			tv.setGravity(Gravity.CENTER);
			tv.setText("测试" + i);
			data.add(tv);
		}
		fl.setCondViews(data);
		fl.setCondPos(0, 2);

		bt = (Button) findViewById(R.id.bt);
		bt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				List<View> data = new ArrayList<View>();
				int[] c1 = { Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW, Color.MAGENTA, Color.DKGRAY };
				for (int i = 0; i < c1.length; i++) {
					TextView tv = new TextView(CondSelActivity.this);
					tv.setBackgroundColor(c1[i]);
					tv.setGravity(Gravity.CENTER);
					tv.setText("试试" + i);
					data.add(tv);
				}
				fl.setAreaSelect(true);
				fl.setCondViews(data);
				fl.setCondPos(1, 4);

			}
		});

		tv = (TextView) findViewById(R.id.tv);

		scs = (CondSelectSimple) findViewById(R.id.f2);
		scs.setAreaSelect(true);
		scs.setTxtColor(Color.BLACK, Color.BLACK);
		scs.setTxtBg(this.getResources().getDrawable(R.drawable.con_bg));
		scs.setRefBg(this.getResources().getDrawable(R.drawable.con_sel));
		scs.setOnCondListener(new OnCondListener() {

			@Override
			public void OnSelected(int pos1, int pos2) {
				tv.setText(pos1 + "---" + pos2);

			}

			@Override
			public void OnMoving(int pos1, int pos2) {
				tv.setText(pos1 + "---" + pos2);
			}
		});

		List<CondSimpleVO> list = new ArrayList<CondSimpleVO>();
		for (int i = 1; i <= 12; i++) {
			list.add(new CondSimpleVO(i + "月", i));
		}
		scs.setSimpleData(list);
		scs.setCondPos(3, 9);
	}
}

